// 请求字典key列表
export const dictKeyList = new Set([
  'ZH_FXPG_XB', // 性别
  'ZH_FXPG_SF' // 是否
])

const state = {}

dictKeyList.forEach(key => {
  state[key] = []
})

const mutations = {
  SET_DICT: (state, { key, data }) => {
    state[key] = data
  }
}

const actions = {
  // 设置单字典
  async setDict({ commit }, key) {
    try {
      const { data } = await Promise.reject({})
      commit('SET_DICT', {
        key: key,
        data
      })
    } catch (error) {
      console.error(`获取字典 ${key} error =>`, error)
    }
  },
  // 获取全部字典
  async setDictAll({ dispatch }) {
    try {
      await Promise.all([...dictKeyList].map(async key => await dispatch('setDict', key)))
    } catch (error) {
      console.error(`获取字典 All error =>`, error)
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
